/*----------------------------------------------------------------------------*\
|
|						Public Interface to Muse Technology
|
|							     www.Muse.com
| Author : SunJun 
| Email : sundoom@msn.com
\*----------------------------------------------------------------------------*/

//////////////////////////////////////////////////////////////////////////
// $Id: Vector2.h,v 1.1 2008/12/20 12:20:35 sunjun Exp $
//////////////////////////////////////////////////////////////////////////

#ifndef __Vector2__
#define __Vector2__

//////////////////////////////////////////////////////////////////////////

#if defined __cplusplus

//////////////////////////////////////////////////////////////////////////

#include <Muse.h>

//////////////////////////////////////////////////////////////////////////

NAMESPACE_BEGIN

//////////////////////////////////////////////////////////////////////////

	class API Vector2
	{
    public:		
		// default constructor leaves data uninitialized.
        INLINE Vector2();

		// assigns scalar parameter to all elements. useful to initialize to zero or one.
		explicit INLINE Vector2(F32);

		// initializes from 2 scalar parameters.
        INLINE Vector2(F32 x,F32 y);

		// initializes from an array of scalar parameters.
		INLINE Vector2(const F32 v[]);

		// copy constructor.
		INLINE Vector2(const Vector2& rhs);

		INLINE const Vector2& operator=(const Vector2&);

		// returns TRUE if this and arg's elems are within epsilon of each other.
		INLINE BOOL equals(const Vector2 &, F32 epsilon) const;
		
		// returns TRUE if the two vectors are exactly equal.
        INLINE BOOL operator == (const Vector2& v) const;

		// returns FALSE if the two vectors are exactly equal.
        INLINE BOOL operator != (const Vector2& v) const;
		
		// TRUE if all the members are smaller.
        INLINE BOOL operator <  (const Vector2& v) const;
		
		// access the data as an array.
        INLINE F32 * ptr();
        INLINE const F32 * ptr() const;
		
		// set methods
        INLINE VOID set( F32 x, F32 y );
		INLINE VOID set( const Vector2& rhs);
		
        INLINE F32 & operator [] (U32 i);
        INLINE F32 operator [] (U32 i) const;
		
        INLINE F32 & x();
        INLINE F32 & y();
		
        INLINE F32 x() const;
        INLINE F32 y() const;        
		
        // dot product.
        INLINE F32 operator * (const Vector2& rhs) const;
		
        // multiply by scalar.
        INLINE const Vector2 operator * (F32 rhs) const;
		
        // unary multiply by scalar.
        INLINE Vector2& operator *= (F32 rhs);
		
        // divide by scalar.
        INLINE const Vector2 operator / (F32 rhs) const;
		
        // unary divide by scalar.
        INLINE Vector2& operator /= (F32 rhs);
		
        // binary vector add.
        INLINE const Vector2 operator + (const Vector2& rhs) const;
		
        // unary vector add. slightly more efficient because no temporary intermediate object.
        INLINE Vector2& operator += (const Vector2& rhs);
		
        // binary vector subtract.
        INLINE const Vector2 operator - (const Vector2& rhs) const;
		
        // unary vector subtract.
        INLINE Vector2& operator -= (const Vector2& rhs);
		
        // negation operator. returns the negative of the vector.
        INLINE const Vector2 operator - () const;
		
        // length of the vector = sqrt( vec . vec )
        INLINE F32 length() const;
		
        // length squared of the vector = vec . vec
        INLINE F32 length2( VOID ) const;
		
        // normalize the vector so that it has length unity. * returns the previous length of the vector.
        INLINE F32 normalize();

	protected: F32 _v[2];		
	};

//////////////////////////////////////////////////////////////////////////

NAMESPACE_END

//////////////////////////////////////////////////////////////////////////

#endif // __cplusplus

//////////////////////////////////////////////////////////////////////////

#endif

//////////////////////////////////////////////////////////////////////////